package com.woolink.per.service.stat.action;

import org.apache.struts2.interceptor.ServletRequestAware;

import com.woolink.per.common.BaseAction;
import com.woolink.per.common.Constants;
import com.woolink.per.common.ErrorCodes;
import com.woolink.per.common.Result;
import com.woolink.per.log.syslog.RunLog;
import com.woolink.per.service.stat.pojo.StatData;
import com.woolink.per.service.stat.service.StatDataService;

public class StatDataAction extends BaseAction implements ServletRequestAware
{
    /**
     * 意义，目的和功能，以及被用到的地方<br>
     */
    private static final long serialVersionUID = 1L;
    
    /**
     * 日志
     */
    private RunLog runLog;
    
    private StatDataService statDataService;
    
    private StatData statData;
    
    public String potal()
    {
        try
        {
            params.put("type", "cpi");
            params.put("startDate", "2002");
            params.put("endDate", "2005");
            
            Result result = statDataService.queryChartXml(params, request);
            
            int resultCode = result.getResultCode();
            
            if (ErrorCodes.ERRORCODE_SUCC == resultCode)
            {
                getRequest().setAttribute("xmlStr", (String)result.getResultPojo());
                
                return null;
            }
            else
            {
                message = getText(Constants.MESSAGE_PREFIX + resultCode);
                return ERROR;
            }
        }
        catch (Exception e)
        {
            runLog.error("Unknow Error!", e, request);
            message = getText(Constants.MESSAGE_PREFIX
                    + ErrorCodes.ERRORCODE_UNKNOW);
            return ERROR;
        }
    }
    
    /**
     * 
     * Description: 分页查询<br>
     * Implement: <br>
     * @return
     * @see
     * @return String
     * @author develop
     */
    public String list()
    {
        try
        {
            /*// 如果从菜单进入，即在没有分页信息的情况下，则默认进入首页
            if (null == page)
            {
                page = new Page();
                page.setCurPage(1);
            }
            
            // 调用而业务层进行分页查询
            Result result = orderInfoService.queryForPages(page, queryCondition);
            
            int resultCode = result.getResultCode();
            if (ErrorCodes.ERRORCODE_SUCC == resultCode)
            {
                QueryResults queryResults = (QueryResults)result.getResultPojo();
                
                // 获取服务代码结果集
                runLog.debug(queryResults);
                results = queryResults.getResults();
                
                // 获取分页信息
                page = queryResults.getPage();
                
                // 跳转到分页页面
                return SUCCESS;
            }
            else
            {
                message = getText(Constants.MESSAGE_PREFIX + resultCode);
                return ERROR;
            }*/
            
            return "";
        }
        catch (Exception e)
        {
            runLog.error("Unknow Error!", e, request);
            message = getText(Constants.MESSAGE_PREFIX
                    + ErrorCodes.ERRORCODE_UNKNOW);
            return ERROR;
        }
    }
    
    /**
     * 
     * Description: 添加订单信息
     * Implement: <br>
     * @see
     * @return String 跳转标识
     */
    @SuppressWarnings("rawtypes")
    public String doAdd()
    {
        try
        {
            /*runLog.debug("orderInfo=" + orderInfo);
            // 查找分销商信息
            Result distributorResult = orderInfoService.queryDistributorByName(orderInfo.getDistributorInfo());
            
            int distributorResultCode = distributorResult.getResultCode();
            
            if (ErrorCodes.ERRORCODE_SUCC != distributorResultCode)
            {
                message = getText(Constants.MESSAGE_PREFIX + distributorResultCode);
                actResult = Constants.ACTRESULT_FAIL;
                return ERROR;
            }
            
            // 订单创建时间
            Result result = orderInfoService.addOneOrder(orderInfo, request);
            
            int resultCode = result.getResultCode();
            message = getText(Constants.MESSAGE_PREFIX + resultCode);
            if (ErrorCodes.ERRORCODE_SUCC == resultCode)
            {
                actResult = Constants.ACTRESULT_SUC;
                return SUCCESS;
            }
            else
            {
                actResult = Constants.ACTRESULT_FAIL;
                return ERROR;
            }*/
            
            return "";
        }
        catch (Exception e)
        {
            runLog.error("Unknow Error!", e, request);
            actResult = Constants.ACTRESULT_FAIL;
            message = getText(Constants.MESSAGE_PREFIX
                    + ErrorCodes.ERRORCODE_UNKNOW);
            return ERROR;
        }
        
    }
    
    /**
     * 
     * Description: 预添加
     * Implement: <br>
     * @see
     * @return String 跳转标识
     */
    public String toAdd()
    {
        try
        {
            return SUCCESS;
        }
        catch (Exception e)
        {
            runLog.error("Unknow Error!", e, request);
            message = getText(Constants.MESSAGE_PREFIX
                    + ErrorCodes.ERRORCODE_UNKNOW);
            return ERROR;
        }
    }
    
    /**
     * 
     * Description: 预修改订单信息
     * Implement: <br>
     * @see
     * @return String 跳转标识
     */
    public String toMod()
    {
        try
        {
            /*// 调用业务层获取一个路由对象
            Result result = orderInfoService.viewOneOrder(innerIndex);
            int resultCode = result.getResultCode();
            if (ErrorCodes.ERRORCODE_SUCC == resultCode)
            {
                orderInfo = (OrderInfo)result.getResultPojo();
                return SUCCESS;
            }
            else
            {
                message = getText(Constants.MESSAGE_PREFIX + resultCode);
                return ERROR;
            }*/
            
            return "";
        }
        catch (Exception e)
        {
            runLog.error("Unknow Error!", e, request);
            message = getText(Constants.MESSAGE_PREFIX
                    + ErrorCodes.ERRORCODE_UNKNOW);
            return ERROR;
        }
    }
    
    public String doMod()
    {
        try
        {
            /*// 打印入口信息
            runLog.debug("orderInfo=" + orderInfo);
            
            // 调用业务层进行路由的修改操作
            Result result = orderInfoService.modOneOrder(orderInfo, request);
            int resultCode = result.getResultCode();
            message = getText(Constants.MESSAGE_PREFIX + resultCode);
            if (ErrorCodes.ERRORCODE_SUCC == resultCode)
            {
                actResult = Constants.ACTRESULT_SUC;
                return SUCCESS;
            }
            else
            {
                actResult = Constants.ACTRESULT_FAIL;
                return ERROR;
            }*/
            return "";
        }
        
        catch (Exception e)
        {
            runLog.error("Unknow Error!", e, request);
            actResult = Constants.ACTRESULT_FAIL;
            message = getText(Constants.MESSAGE_PREFIX
                    + ErrorCodes.ERRORCODE_UNKNOW);
            return ERROR;
        }
    }
    
    public String toDetail()
    {
        try
        {
            /*// 调用业务层获取一个路由对象
            Result result = subOrderInfoService.viewOneSubOrder(innerIndex);
            int resultCode = result.getResultCode();
            if (ErrorCodes.ERRORCODE_SUCC == resultCode)
            {
                subOrderInfo = (SubOrderInfo)result.getResultPojo();
                return SUCCESS;
            }
            else
            {
                message = getText(Constants.MESSAGE_PREFIX + resultCode);
                return ERROR;
            }
            */
            return "";
        }
        catch (Exception e)
        {
            runLog.error("Unknow Error!", e, request);
            message = getText(Constants.MESSAGE_PREFIX
                    + ErrorCodes.ERRORCODE_UNKNOW);
            return ERROR;
        }
    }
    
    public String doDel()
    {
        try
        {
            /*runLog.debug("doDel");
            // 调用业务层进行路由的删除操作
            Result result = orderInfoService.delOrders(innerIndexs, request);
            int resultCode = result.getResultCode();
            
            if (ErrorCodes.ERRORCODE_SUCC == resultCode)
            {
                message = getText(Constants.MESSAGE_PREFIX + resultCode);
                actResult = Constants.ACTRESULT_SUC;
                return SUCCESS;
            }
            // 如果删除中出现失败
            else
            {
                // 取得删除失败的条数
                int delErrorNum = result.getDelErrorNum();
                // 根据总条数和失败条数得出成功的条数
                int delSuccNum = innerIndexs.length - delErrorNum;
                // 定义国际化消息的参数
                String[] params = new String[] {String.valueOf(delSuccNum),
                        String.valueOf(delErrorNum)};
                message = getText(Constants.MESSAGE_PREFIX + resultCode, params);
                actResult = Constants.ACTRESULT_FAIL;
                return ERROR;
            }*/
            
            return "";
        }
        catch (Exception e)
        {
            runLog.error("Unknow Error!", e, request);
            actResult = Constants.ACTRESULT_FAIL;
            message = getText(Constants.MESSAGE_PREFIX
                    + ErrorCodes.ERRORCODE_UNKNOW);
            return ERROR;
        }
    }

    /**
     * @param runLog The runLog to set.
     */
    public void setRunLog(RunLog runLog)
    {
        this.runLog = runLog;
    }

    /**
     * @param statDataService The statDataService to set.
     */
    public void setStatDataService(StatDataService statDataService)
    {
        this.statDataService = statDataService;
    }

    /**
     * @param statData The statData to set.
     */
    public void setStatData(StatData statData)
    {
        this.statData = statData;
    }

    /**
     * @return Returns the statData.
     */
    public StatData getStatData()
    {
        return statData;
    }
    
}
